package database
import(
	"fmt"
	"github.com/jinzhu/gorm"
	_"github.com/jinzhu/gorm/dialects/mysql"
)

var DbclientFishAll *gorm.DB

// func DbConn(MyUser, Password, Host, Db string, Port int) *gorm.DB {
func DbConn(dataBaseName Dbconfig) *gorm.DB {
	connArgs := fmt.Sprintf("%s:%s@(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local", dataBaseName.DBServerUsesrName,dataBaseName.DBServerPassword, dataBaseName.DBServerAddr, dataBaseName.DBServerPort, dataBaseName.CountDBName )
	fmt.Println(connArgs)
	db, err := gorm.Open("mysql", connArgs)
	if err != nil {
		fmt.Println(err.Error())
	}
	db.SingularTable(true)
	return db
}


func Connect() {
	DbclientFishAll = DbConn(G_JsonConfig.FishAll)
}